package socket1;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Scanner;

/**
 * @classname:SocketService
 * @description:
 * @author: Mr.Z
 * @date: 2020/12/21 19:12
 * @version: 0.1
 * @since:1.8
 */
public class SocketService {
    public static void main(String[] args) {
        final String serviceName = "赵鑫阳：";
        final Scanner input = new Scanner(System.in);
        try {
            ServerSocket serverSocket = new ServerSocket(8888);
            System.out.println("服务器端开启");

            while (true) {
                Socket accept = serverSocket.accept();
                DataOutputStream dataOutputStream = new DataOutputStream(accept.getOutputStream());
                System.out.println(serviceName);
                dataOutputStream.writeUTF(serviceName+input.nextLine());

                DataInputStream dataInputStream = new DataInputStream(accept.getInputStream());
                System.out.println(dataInputStream.readUTF());
            }

        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
